﻿using AutoMapper;
using Infrastructure.Extend;
using Infrastructure.Web;
using MyData.ApiDto;
using MyData.Dto;
using MyData.Models;
using MyDomain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyApplication
{
    public class VisitorApp
    {
        private IVisitorRepository _visitorService;
        public VisitorApp(IVisitorRepository visitorService)
        {
            _visitorService = visitorService;
        }
        public PageDto<VisitorDto> GetVisitor(QueryListModel query, Guid departId, string company)
        {
            var expression = ExtLinq.True<Visitor>();
            if (departId != Guid.Empty)
            {
                expression = expression.And(t => t.DepartId == departId);
            }
            if (!string.IsNullOrEmpty(company))
            {
                expression = expression.And(t => t.Company.Contains(company));
            }
            var result = _visitorService.IQueryable(expression).OrderByDescending(t => t.CreatedTime).Paging(query.Limit, query.Offset);
            return new PageDto<VisitorDto>()
            {
                total = result.total,
                rows = Mapper.Map<List<Visitor>, IList<VisitorDto>>(result.rows.ToList())
            };
        }

        public bool VisitorDelete(Guid Id)
        {
            return _visitorService.DeleteVisitor(Id);
        }
        public VisitorDto CheckVisitor(Guid Id)
        {
            var entity = _visitorService.FindEntity(Id);
            return Mapper.Map<Visitor, VisitorDto>(entity);
        }
        public bool Save(Visitor visitor)
        {
            return _visitorService.SaveVisitor(visitor);
        }
        public bool SaveConfirmVisitor(Visitor visitor)
        {
            return _visitorService.SaveConfirmVisitor(visitor);
        }
        public bool SaveMeet(MeetUser meetUser)
        {
            return _visitorService.SaveMeet(meetUser);
        }
        public PageDto<MeetUserDto> GetCompanyUser(QueryListModel query, string company, string meetId)
        {
            return _visitorService.GetCompanyUser(query, company, meetId);
        }
        public bool CompanyDelete(Guid Id)
        {
            return _visitorService.DeleteCompanyUser(Id);
        }
        public MeetUserDto CheckCompany(Guid Id)
        {
            return _visitorService.GetCompany(Id);
        }
        public WelDto GetWelDto()
        {
            return _visitorService.GetWelDto();
        }
        public SynsMeetUser GetSynsMeetUser(Guid mobileId)
        {
            return _visitorService.GetSynsMeetUser(mobileId);
        }
        public bool VisitorConfirm(Guid Id)
        {
            return _visitorService.VisitorConfirm(Id);
        }
        public bool DeleteVisitorOutTime()
        {
            return _visitorService.DeleteVisitorOutTime();
        }
    }
}
